package com.wingsboat;

import java.util.Scanner;

/**
 * @author wangzhong
 * @description: TODO
 * @date 2024/7/20 11:16
 */
public class Test7 {
    
    public static void main(String[] args){
        CircleNode list = new CircleNode();
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        for(int i=1;i<=num;i++){
            list.addNode(i);
        }
        Node7 cur = list.getHeader();
        int a =1;
        while(list.getSize()>1){
            if(a==3){
                list.remove(cur);
                a = 1;
            }else{
                a = a+1;
            }
            cur =cur.getNext();
        }
        System.out.println(cur.getNum());
    }
}

class CircleNode{
    private Node7 header;
    private Node7 tail;
    private int size;

    // 新增节点，维护size
    public void addNode(int num){
        Node7 node = new Node7(num);
        // 空节点
        if(size==0){
            header = node;
            tail = node;
        }else{
            tail.setNext(node);
            node.setPre(tail);
            tail = node;
        }
        // 维护循环
        header.setPre(tail);
        tail.setNext(header);
        size++;
    }

    public void remove(Node7 node){
        if(size==1){
            header = tail = null;
        }else{
            Node7 pre = node.getPre();
            Node7 next = node.getNext();
            pre.setNext(next);
            next.setPre(pre);
            if(header== node) header = next;
            if(tail == node) tail = pre;
        }
        size--;
    }

    public void print(){
        Node7 cur = header;
        int i = size;
        while(i>0){
            System.out.println(cur.getNum());
            cur = cur.getNext();
            i = i-1;
        }
    }

    public int getSize(){
        return size;
    }

    public Node7 getHeader() {
        return header;
    }
}
class Node7{
    private int num;
    
    private Node7 next;
    
    private Node7 pre;
    
    public Node7(int num){
        this.num = num;
        this.next = null;
        this.pre = null;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public Node7 getNext() {
        return next;
    }

    public void setNext(Node7 next) {
        this.next = next;
    }

    public Node7 getPre() {
        return pre;
    }

    public void setPre(Node7 pre) {
        this.pre = pre;
    }
}
